package com.czxy.blogs.manage.service.impl;

import com.czxy.blogs.dao.FriendLinkMapper;
import com.czxy.blogs.domain.Friendlink;
import com.czxy.blogs.manage.service.FriendLinkService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class FriendLinkServiceImpl implements FriendLinkService {

    @Autowired
    private FriendLinkMapper friendLinkMapper;

    @Override
    public PageInfo<Friendlink> findAllFriendLink(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Friendlink> list = friendLinkMapper.selectAll();
        return new PageInfo<Friendlink>(list);
    }

    @Override
    public void deleteFLinks(String... fids) {
        if (fids != null) {
            for (String fid : fids) {
                friendLinkMapper.deleteByPrimaryKey(fid);
            }
        }
    }

    @Override
    public Friendlink view(String fid) {
        return friendLinkMapper.selectByPrimaryKey(fid);
    }

    @Override
    public void updateFlink(Friendlink friendlink) {
        Example example = new Example(Friendlink.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("fid",friendlink.getFid());
        friendLinkMapper.updateByExampleSelective(friendlink,example);
    }

    @Override
    public void addFlink(Friendlink friendlink) {

        friendLinkMapper.insertSelective(friendlink);
    }


}
